/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年8月29日
 */
package com.massyframework.beanskin.assembly;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.massyframework.beanskin.assembly.beans.BeanContextAdapter;
import com.massyframework.beanskin.assembly.beans.BeanNotFoundException;
import com.massyframework.beanskin.assembly.handling.HandlerBase;

/**
 * 实现{@link AssemblyContext}接口的装配件上下文代理。
 * @author huangkh
 *
 */
public class AssemblyContextDelegate<T extends BeanContextAdapter> extends HandlerBase implements AssemblyContext {
	
	private T beanContext;

	/**
	 * 构造方法
	 * @param beanContext {@link T}, bean容器适配器
	 */
	public AssemblyContextDelegate(T beanContext) {
		this.beanContext = Objects.requireNonNull(beanContext, "\"beanContext\" cannot be null.");
	}

	@Override
	public boolean containsBean(String beanName) {
		return this.beanContext.containsBean(beanName);
	}

	@Override
	public Object getBean(String beanName) throws BeanNotFoundException {
		return this.beanContext.getBean(beanName);
	}

	@Override
	public Class<?> getBeanType(String beanName) throws BeanNotFoundException {
		return this.beanContext.getBeanType(beanName);
	}

	@Override
	public <B> Map<String, B> getBeansOfType(Class<B> beanType) {
		return this.beanContext.getBeansOfType(beanType);
	}

	@Override
	public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annoType) {
		return this.beanContext.getBeansWithAnnotation(annoType);
	}
	

	@Override
	public List<String> getBeanNames() {
		return this.beanContext.getBeanNames();
	}

	@Override
	public String toString() {
		return "AssemblyContextDelegate";
	}
	
	/**
	 * Bean上下文
	 * @return {@link T}
	 */
	public T getBeanContext() {
		return this.beanContext;
	}
	
}
